package com.niiwoo.civet.trade.service.dubbo.project;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.niiwoo.civet.trade.dao.entity.ProjectFlowed;
import com.niiwoo.civet.trade.service.local.project.ProjectFlowService;
import com.niiwoo.civet.trade.service.project.ProjectFlowDubboService;
import com.niiwoo.tripod.lanmao.component.LanMaoDirectService;
import com.niiwoo.tripod.lanmao.component.LanMaoSequence;
import com.niiwoo.tripod.lanmao.enums.ProjectStatusEnum;
import com.niiwoo.tripod.lanmao.request.ModifyProjectRequest;
import com.niiwoo.tripod.lanmao.request.QueryProjectInformationRequest;
import com.niiwoo.tripod.lanmao.response.ModifyProjectResponse;
import com.niiwoo.tripod.lanmao.response.QueryProjectInformationResponse;
import lombok.extern.java.Log;
import lombok.extern.log4j.Log4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Optional;

/**
 * Created by dell on 2018/1/12.
 */

@Service(version = "1.0.0")
public class ProjectFlowDubboServiceImpl implements ProjectFlowDubboService {

    public static final Logger log = LoggerFactory.getLogger(ProjectFlowDubboServiceImpl.class);

	@Autowired
	private ProjectFlowService projectFlowService;

	@Autowired
    LanMaoSequence lanMaoSequence;

    @Autowired
    LanMaoDirectService lanMaoDirectService;

	@Override
	public void overInvestEndTimeFlow() {
		projectFlowService.overInvestEndTimeFlow();
	}

    @Override
    public void syncFlowStatusToLanMao() {
        Optional<List<ProjectFlowed>> projectFlowedOptional = Optional.ofNullable(projectFlowService.getUnsyncFlowList()).filter(list -> !list.isEmpty());
        if (!projectFlowedOptional.isPresent()) {
            log.info("同步流标状态到存管计划任务###未找到记录");
        } else {
            List<ProjectFlowed> projectFloweds = projectFlowedOptional.get();
            log.info("同步流标状态到存管计划任务###记录数={}", projectFloweds.size());
            projectFloweds.forEach(pf -> projectFlowService.syncSingleFlowStatus(pf));
        }

    }

}
